package com.twu.biblioteca.command;

import com.twu.biblioteca.Library.User;
import com.twu.biblioteca.service.LoginService;
import com.twu.biblioteca.tools.UserFactory;
import com.twu.biblioteca.view.MessageView;

import java.util.ArrayList;
import java.util.List;

public class ShowPersonalInformation extends Command {
    private User user;
    private final String USER_ID = "User ID : ";
    private final String USER_NAME = "User name : ";
    private final String EMAIL = "Email : ";
    private final String ADDRESS = "Address : ";
    private final String PHONENUMBER = "Phone number : ";


    public ShowPersonalInformation(MessageView messageView, User user) {
        super(messageView);
        this.user = user;
    }

    @Override
    public void execute() {
        try {
            UserFactory.checkLogin(user);
            getMessageView().showMessageList(buildPersonalInformationList());
        } catch (NullPointerException e) {
            getMessageView().showMessage(MessageView.HAVE_NOT_LOGIN);
        }
    }

    private List<String> buildPersonalInformationList() {

        List<String> personalInformation = new ArrayList<String>();
        personalInformation.add(USER_ID + user.getUserId());
        personalInformation.add(USER_NAME + user.getUserName());
        personalInformation.add(EMAIL + user.getEmail());
        personalInformation.add(ADDRESS + user.getAddress());
        personalInformation.add(PHONENUMBER + user.getPhoneNumber());
        return personalInformation;
    }
}
